package xyz.robinbingo.dailybill.web.rsp;


import cn.hutool.json.JSONObject;

import java.io.Serializable;
import java.util.Map;

/**
 * 通用返回包装类
 *
 * @author Robin
 * @date 2018/8/1 15:02
 **/
public class Rsp implements Serializable {

    private static final long serialVersionUID = 523855044105571330L;

    /******************************fields******************************/

    private int code;

    private String message;

    private JSONObject data;

    /******************************getters&setters******************************/

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public JSONObject getData() {
        return data;
    }

    public void setData(JSONObject data) {
        this.data = data;
    }

    /******************************methods******************************/

    public Rsp() {
        this.code = RspEnum.SUCCESS.getCode();
        this.message = RspEnum.SUCCESS.getMessage();
        this.data = new JSONObject();
    }

    public Rsp(int code, String message) {
        this.code = code;
        this.message = message;
        this.data = new JSONObject();
    }

    public void setRsp(RspEnum rspEnum) {
        this.code = rspEnum.getCode();
        this.message = rspEnum.getMessage();
    }

    public void setRsp(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Rsp put(String name, Object data) {
        this.data.put(name, data);
        return this;
    }

    public Rsp putAll(JSONObject object) {
        this.data.putAll(object);
        return this;
    }
}